package com.yzfarm.biujoke.biujoke.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.yzfarm.biujoke.biujoke.R;
import com.yzfarm.biujoke.biujoke.mvp.model.datamanager.ImageLoadManager;
import com.yzfarm.biujoke.biujoke.mvp.model.datamanager.ImageLoader;
import com.yzfarm.biujoke.biujoke.mvp.view.BrowseBiuActivity;
import com.yzfarm.biujoke.biujoke.ui.viewholder.Star12ViewHolder;
import com.yzfarm.biujoke.biujoke.utils.pojo.NewMeinvItem;

import java.util.List;

/**
 * Created by han on 2015/11/29.
 */
public class Star12RecyclerAdpter extends RecyclerView.Adapter<Star12ViewHolder> {

    private Context mContext;
    private List<NewMeinvItem> mData;
    private ImageLoader imageLoader;
    public Star12RecyclerAdpter(Context context, List<NewMeinvItem> list){
        Log.d("123","Star12RecyclerAdpter");
        mContext = context;
        mData = list;
        imageLoader = ImageLoadManager.getImagerLoader();
    }

    public void setmData(List<NewMeinvItem> mData) {
        this.mData = mData;
    }

    @Override
    public Star12ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Log.d("123","onCreateViewHolder ");
        Star12ViewHolder holder = new Star12ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.star12_item,parent,false));
        return holder;
    }

    @Override
    public void onBindViewHolder(Star12ViewHolder holder, int position) {
        Log.d("123", "mData.get(position) = " + mData.get(position));
        holder.iv.setOnClickListener(cls);
        holder.iv.setTag(R.integer.main_pic_id,position);
        imageLoader.load(mContext,mData.get(position).coverPic,holder.iv,R.mipmap.picdefault);
    }

    private View.OnClickListener cls = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = (Integer) v.getTag(R.integer.main_pic_id);
            Log.d("123", "onClick mData.get(position) = " + mData.get(position));
            Intent in = new Intent();
            in.putExtra("picUrl",mData.get(position).linkhref);
            in.putExtra("picName",mData.get(position).alt);
            in.setClass(mContext, BrowseBiuActivity.class);
            mContext.startActivity(in);

        }
    };

    @Override
    public int getItemCount() {
        return mData.size();
    }
}
